package com.xbongbong.saas.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.constant.TimeConstant;
import com.xbongbong.paas.enums.ConditionEnum;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * 保质期类型枚举
 *
 * @Author: lcx
 * @date: 2019-01-26 10:33
 * @since v1.0
 */
@Getter
public enum GuaranteeStatusEnum {
    /*
     * 保质期类型枚举
     */
    // 已过期
    OUT_OF_DATE(1, "enum.guaranteeStatus.name.out_of_date", 0, ConditionEnum.EQUAL.getSymbol()),
    // 15天内过期
    EXPIRE_IN_FIFTEEN(2, "enum.guaranteeStatus.name.expire_in_fifteen", TimeConstant.SECONDS_PER_DAY * 15, ConditionEnum.LESSEQUAL.getSymbol()),
    // 30天内过期
    EXPIRE_IN_THIRTY(3, "enum.guaranteeStatus.name.expire_in_thirty", TimeConstant.SECONDS_PER_MONTH, ConditionEnum.LESSEQUAL.getSymbol()),
    // 60天内过期
    EXPIRE_IN_SIXTY(4, "enum.guaranteeStatus.name.expire_in_sixty", TimeConstant.SECONDS_PER_MONTH * 2, ConditionEnum.LESSEQUAL.getSymbol()),
    // 60天以上
    EXPIRE_OVER_SIXTY(5, "enum.guaranteeStatus.name.expire_over_sixty", TimeConstant.SECONDS_PER_MONTH * 2, ConditionEnum.GREATEREQUAL.getSymbol()),
    UNKNOW(404,"404",0,ConditionEnum.NOEQUAL.getSymbol()),

    ;

    /** 枚举值 -- */
    private final int code;
    /** 枚举信息--中文名称 */
    private final String    name;
    private final Integer time;
    private final String symbol;

    GuaranteeStatusEnum(int code, String name, Integer time, String symbol) {
        this.code = code;
        this.name = name;
        this.time = time;
        this.symbol = symbol;
    }

    /**
     * 获取全部枚举
     *
     * @return List<AssessTypeEnum>
     */
    public static List<GuaranteeStatusEnum> getAllEnum() {
        List<GuaranteeStatusEnum> list = new ArrayList<>();
        for (GuaranteeStatusEnum cache : values()) {
            if (Objects.equals(cache.getCode(),GuaranteeStatusEnum.UNKNOW.getCode())){
                continue;
            }
            list.add(cache);
        }
        return list;
    }

    /**
     * 根据code获取枚举
     * @return
     */
    public static GuaranteeStatusEnum getByCode(int code) {
        for (GuaranteeStatusEnum cache : values()) {
            if (code == cache.getCode()) {
                return cache;
            }
        }
        return UNKNOW;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }
}
